#######################
#Team Analysis Code#####
######################

#####################
###Group 4 members#####
#Michelle Lin  ########
#Carlos Galian   ######
#Adanna Chukwuma   ####
#######################s

###############################################################################################
####Cash or Condition: Evidence from a Cash Transfer Experiment################################
####By Sarah Baird, Craig McIntosh, and Berk Ozler#############################################
#### The Quarterly Journal of Economics(2011) 126, 1709 -1753###################################
###############################################################################################


#######################
#Pre-analysis code##
#######################


#Set working directory
setwd("C:/Users/Adanna/Dropbox/Replication- Cash or Conditional/Final Code Second Stage")
#setwd("D:/Quantitative Methods/Paper/Cash or Condition/Final - replication")


#open packages
library(foreign)


# open dataset
data<-read.dta("C:/Users/Adanna/Desktop/Replication/Datasets/second_stata.dta", 
               convert.factors=F, convert.underscore=T) #remove underscore
data<-read.dta("D:/Quantitative Methods/Paper/Cash or Condition/second_stata.dta", 
               convert.factors=F, convert.underscore=T) #remove underscore


#create sample data
sample<-subset(data, sample.SG==1)


#generate variables for intervention
sample$condition_T2a<-ifelse(sample$T2a==1,1,
                             ifelse(sample$T2a!=1 & sample$C2==1,0,"NA"
                             ))#for conditional cash transfers with control as C2

sample$condition_T2b<-ifelse(sample$T2b==1,1,
                             ifelse(sample$T2b!=1 & sample$C2==1,0,"NA"
                             ))#for unconditional cash transfers with control as C2

#generate variables for money transfer
sample$monthly_money_T2a<-as.numeric(ifelse(sample$T2a==1,((sample$hh.amount+sample$individual.amount)-((min(sample$hh.amount+sample$individual.amount,na.rm=T))-1)),#make the lowest Rx class 1
                                            ifelse(sample$T2a!=1 & sample$C2==1,0,"NA")))#Total money for conditional cash transfer rebased by lowest amount

sample$monthly_money_T2b<-as.numeric (ifelse(sample$T2b==1,((sample$hh.amount+sample$individual.amount)-((min(sample$hh.amount+sample$individual.amount,na.rm=T))-1)),#make the lowest Rx class 1
                                             ifelse(sample$T2b!=1 & sample$C2==1,0,"NA")))#Total money for unconditional cash transfer rebased by lowest amount


#create panel dataset (refer to page 1724-1725)
dataset<-subset(sample,panel==1)#2089 girlsin 3 rounds and sample


